package com.lzrj.server;

import com.beust.jcommander.DynamicParameter;
import com.beust.jcommander.Parameter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CmdArgOption {


    @Parameter(names = {"-d","--basedir"}, description = "运行时路径")
    private String basedir;

    @Parameter(names = {"-h","--hostname"}, description = "主机名")
    private String hostname;

    @Parameter(names = {"-w","--webapp"}, description = "运行项目的根路径 <context:webpath or webpath>")
    private List<String> webapp;

    @Parameter(names = {"-c","--context"}, description = "项目前缀名")
    private List<String> context;

    @Parameter(names = {"-p","--port","--server.port"}, description = "部署项目运行的端口号")
    private Integer serverPort;

    @Parameter(names = {"-pk","--pkill"}, description = "停止对应web端口运行的tomcat进程")
    private Integer[] pkillPort;

    @Parameter(names = {"-help","--help"}, description = "help",help = true)
    private boolean help;

    @Parameter(names = {"-v","--version"}, description = "web server版本号", help = true, order = 6)
    private boolean version;

    @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
    private Map<String, String> dynamicParams = new HashMap<>();

    @Parameter(names = {"-J","-jvm","--jvm"}, description = "Jvm parameters go here")
    private List<String> jvmParams = new ArrayList<>();

    public String getHostname() {
        if (hostname == null || hostname.equals("")){
            hostname = "127.0.0.1";
        }
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public List<String> getWebapp() {
        return webapp;
    }


    public List<Webapp> getParseWebapp() {
        return Webapp.parse(getWebapp(),getContext());
    }


    public void setWebapp(List<String> webapp) {
        this.webapp = webapp;
    }

    public List<String> getContext() {
        return context;
    }

    public void setContext(List<String> context) {
        this.context = context;
    }

    public Integer getServerPort() {
        if (serverPort == null || serverPort.equals(0)){
            serverPort = 8080;
        }
        return serverPort;
    }

    public void setServerPort(Integer serverPort) {
        this.serverPort = serverPort;
    }

    public Integer[] getPkillPort() {
        return pkillPort;
    }

    public void setPkillPort(Integer[] pkillPort) {
        this.pkillPort = pkillPort;
    }

    public String getBasedir() {
        if (basedir == null || basedir.equals("")){
            basedir = "./.webserver_run";
        }
        return basedir;
    }

    public void setBasedir(String basedir) {
        this.basedir = basedir;
    }

    public boolean isHelp() {
        return help;
    }

    public void setHelp(boolean help) {
        this.help = help;
    }

    public boolean isVersion() {
        return version;
    }

    public void setVersion(boolean version) {
        this.version = version;
    }

    public Map<String, String> getDynamicParams() {
        return dynamicParams;
    }

    public void setDynamicParams(Map<String, String> dynamicParams) {
        this.dynamicParams = dynamicParams;
    }

    public List<String> getJvmParams() {
        return jvmParams;
    }

    public void setJvmParams(List<String> jvmParams) {
        this.jvmParams = jvmParams;
    }
}
